#ifndef TC_CIRCARRAY_HPP
#define TC_CIRCARRAY_HPP

/** \file CircArray.hpp
 * Declarations for the templated class CircArray.
 *
 * (c) Copyright by Semih Cemiloglu
 * All rights reserved, see COPYRIGHT file for details.
 *
 * $Id: CircArray.hpp 119 2006-06-21 04:57:25Z semihc $
 *
 *
 */

#include "Global.hh"
#include "DBC.hpp"

namespace TC {

  /**
     Circular array structure to operate upon the elements.
   */
  TC_EXPORT template <typename T>
  class CircArray 
  {
  public:
    // CREATORS
    CircArray(const unsigned lmt) 
      : m_lmt(lmt), m_cnt(0), m_idx(0), m_sum(0), m_arr(new T[lmt]) 
    { TC_PRE_CONDITION(lmt > 0); }

    ~CircArray() 
    { delete[] m_arr; }

    // ACCESSORS
    //! Check if the array is empty
    bool empty() const { return m_cnt==0; }
    //! Get the size of the array
    unsigned size() const { return m_cnt; }
    //! Calculate summation of all elements
    T sum() const { return m_sum; }
    //! Find the maximum element
    T max() const;
    //! Find the minimum element
    T min() const;
    //! Calculate simple average of all elements
    T avg() const;
    //! Get an element of the array with a given position
    T at(unsigned pos) const;

    // MODIFIERS
    void push(const T val);

  private:
    // NOT ALLOWED
    CircArray();
    CircArray(const CircArray&);
    void operator=(const CircArray&);

    // MEMBERS
    //! The limit or size of the array
    const unsigned m_lmt; 
    //! The count of elements inside the array
    unsigned m_cnt;
    //! Current index to the array which new element go
    unsigned m_idx;
    //! Accumulated sum
    T m_sum;
    //! Pointer to the array
    T* m_arr;

  }; // end class


} // end namespace



#if !defined(TC_USE_EXPORT) && !defined(TC_CIRCARRAY_CPP)
# include "CircArray.cpp"
#endif


#endif /* TC_CIRCARRAY_HPP */
